package com.zbf.user;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zbf.common.entity.ResponseResult;
import com.zbf.common.entity.ResponseResultEnum;
import com.zbf.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 作者: LCG
 * 日期: 2020/5/30 22:46
 * 描述:
 */

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserDao userDao;

    @Autowired
    private UserService userService;

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

  /*  @RequestMapping("/hello")
    public String test() throws AuthException {
        if(1==1){
            throw new AuthException("没有权限");
        }        System.out.println("================hello");
        return "hello";
    }*/


    /**
     * 查询用户列表 查询所有的用户列表
     * @return
     */
    @RequestMapping("/getUserList")
    public ResponseResult getUserList(){
        //设置查询的页码和每页的大小这个必须放在查询的前边
        PageHelper.startPage(0, 10);
        List<Map<String, Object>> pageList = userDao.getPageList();
        //设置分页信息
        PageInfo<Map<String,Object>> pageInfo=new PageInfo<>(pageList);
        ResponseResult responseResult = ResponseResult.getResponseResult();
        responseResult.setResult(pageInfo);
        return responseResult;
    }




    /**
     * 给用户绑定角色
     * @return
     */
    @RequestMapping("/bindRoleForUser")
    public ResponseResult yoBindRoleForUser(@RequestBody Map<String,Object> map){

        if(map.get("userId")!=null&&!map.get("userId").equals("")&&map.get("roleIds")!=null){
            userService.insertRoleUser(map);
        }
        ResponseResult responseResult = ResponseResult.getResponseResult();
        responseResult.setCode(ResponseResultEnum.SECCESS.getCode());

        return responseResult;
    }
}
